package com.miyake.loveviewweb.client.viewer.table;

import java.util.ArrayList;
import java.util.List;

import com.miyake.loveviewweb.shared.model.DataColumnModel;

public class TableDataSwapper {
    private List<DataColumnModel> columns;

    public TableDataSwapper(List<DataColumnModel> columns) {
        this.columns = columns;
    }
    
    public List<String[]> get() {
        int rows = columns.get(0).getValue().length;
        int cols = columns.size();

        String[][] data = new String[cols][rows];
        int col = 0;
        for (DataColumnModel column : columns) {
            for (int row = 0; row < rows; row++) {
                data[col][row] = column.getValue()[row];
            }
            col++;
        }
        
        List<String[]> ret = new ArrayList<String[]>();
        
        for (int r = 0; r < rows; r++) {
            String[] d = new String[cols];
            for (int c = 0; c < cols; c++) {
                d[c] = data[c][r];
            }
            ret.add(d);
        }
        
        
        return ret;
    }
}
